package com.example.demo.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.domain.User;
import com.example.demo.mapper.Usermapper;
import com.example.demo.web.CheckPhonenum;


@Service
public class Userservice {

	@Autowired
	private Usermapper usermapper;

	public int insertUser(String id, String name) {
		int a = usermapper.findid(id);
		if (a == 1) {

			return 2;
		} else {
			 if(CheckPhonenum.isMobileNO(id)==true){
					
				 usermapper.insertUser2(id, name);
				} else{
					
					 usermapper.insertUser(id, name);
				}
			
			return 1;
		}

	}

	public int loginuser(String id, String name) {
		int a = usermapper.findcount(id, name);
		if (a == 1) {
			return 1;
		} else {
			return 2;
		}
	}
	public List<User> serchall(){
		
		System.out.println(usermapper.serchall());
		return usermapper.serchall();
		
		
	}
	public User serchOne(String a ){
		
		return usermapper.serchOne(a);
		
	}
	public int updateuser(String userid,String userpwd)
	{
		
		return usermapper.updateuser(userid,userpwd);
	}

	public void deleteUser(String userid) {
		
		usermapper.deleteuser(userid);
	}

	public int selectbyid(String userid) {
		
		System.out.println(userid);
		System.out.println(usermapper.selectbyid(userid));
		return usermapper.selectbyid(userid);
	}
}
